package de.jmda.gen.java.impl;

import static de.jmda.util.StringUtil.sb;
import de.jmda.gen.GeneratorException;
import de.jmda.gen.impl.DefaultGenerator;
import de.jmda.gen.java.FieldNameGenerator;
import de.jmda.util.StringUtil;

public class DefaultFieldNameGenerator
		extends DefaultGenerator
		implements FieldNameGenerator
{
	public final static String DEFAULT_FIELD_NAME = "field_name";

	public DefaultFieldNameGenerator()
  {
	  super();
  }

	public DefaultFieldNameGenerator(String input)
  {
	  super(input);
  }

	@Override
  public StringBuffer generate() throws GeneratorException
  {
		StringBuffer result = super.generate();
		
		if (StringUtil.isBlank(result))
		{
			result = sb(DEFAULT_FIELD_NAME);
		}

		return result;
  }

	protected StringBuffer validate(StringBuffer stringBuffer)
			throws GeneratorException
	{
		if (false == StringUtil.startsWithLower(stringBuffer))
		{
			throw new GeneratorException(
					stringBuffer + " has to start with lower case");
		}

		return stringBuffer;
	}
}